package com.gpframework.module.controller.module;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.gpframework.common.annotation.Log;
import com.gpframework.common.core.controller.BaseController;
import com.gpframework.common.core.domain.AjaxResult;
import com.gpframework.common.enums.BusinessType;
import com.gpframework.module.module.domain.GpQualityFeedbackQuestion;
import com.gpframework.module.module.domain.vo.GpQualityFeedbackQuestionVo;
import com.gpframework.module.module.domain.req.GpQualityFeedbackQuestionReq;
import com.gpframework.module.module.domain.req.GpQualityFeedbackQuestionAdd;
import com.gpframework.module.module.domain.req.GpQualityFeedbackQuestionUpdate;
import com.gpframework.module.module.service.IGpQualityFeedbackQuestionService;
import com.gpframework.common.utils.poi.ExcelUtil;
import javax.validation.Valid;
import io.swagger.annotations.*;
import com.gpframework.common.core.page.TableDataInfo;
/**
 * @ClassName GpQualityFeedbackQuestionController
 * @Author gpframework
 * @Date 2023-12-14
 * @Version 1.0.0
 * @Description 品质反馈问题Controller
 */
@Validated
@Api(tags = "品质反馈问题")
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@SuppressWarnings({"rawtypes","unchecked"})
@RequestMapping("/module/feedbackquestion" )
public class GpQualityFeedbackQuestionController extends BaseController {

    private final IGpQualityFeedbackQuestionService iGpQualityFeedbackQuestionService;

 /**
  * @Description 分页
  * @Author gpframework
  * @Date 2023-12-14
  * @Param gpQualityFeedbackQuestion
  * @Return TableDataInfo
 */
    @ApiOperation("列表")
    @PreAuthorize("@ss.hasPermi('module:feedbackquestion:list')")
    @GetMapping("/list")
    public TableDataInfo<GpQualityFeedbackQuestionVo> list(GpQualityFeedbackQuestionReq gpQualityFeedbackQuestionReq)
    {
        startPage();
        QueryWrapper<GpQualityFeedbackQuestion> lqw = new QueryWrapper<GpQualityFeedbackQuestion>();
        gpQualityFeedbackQuestionReq.generatorQuery(lqw,true);
        List<GpQualityFeedbackQuestionVo> list = iGpQualityFeedbackQuestionService.listVo(lqw);
        return getDataTable(list);
    }

    /**
     * @Description 新增
     * @Author gpframework
     * @Date 2023-12-14
     * @Param gpQualityFeedbackQuestion
     * @Return TableDataInfo
     */
    @ApiOperation("新增")
    @PreAuthorize("@ss.hasPermi('module:feedbackquestion:add')" )
    @Log(title = "添加品质反馈问题" , businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Valid @RequestBody GpQualityFeedbackQuestionAdd gpQualityFeedbackQuestionAdd) {
        GpQualityFeedbackQuestion gpQualityFeedbackQuestion = Convert.convert(new TypeReference<GpQualityFeedbackQuestion>() {}, gpQualityFeedbackQuestionAdd);
        return toAjax(iGpQualityFeedbackQuestionService.save(gpQualityFeedbackQuestion) ? 1 : 0);
    }

    /**
     * @Description 修改
     * @Author gpframework
     * @Date 2023-12-14
     * @Param gpQualityFeedbackQuestion
     * @Return TableDataInfo
     */
    @ApiOperation("修改")
    @PreAuthorize("@ss.hasPermi('module:feedbackquestion:edit')" )
    @Log(title = "修改品质反馈问题" , businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Valid @RequestBody GpQualityFeedbackQuestionUpdate gpQualityFeedbackQuestionUpdate) {
        GpQualityFeedbackQuestion gpQualityFeedbackQuestion = Convert.convert(new TypeReference<GpQualityFeedbackQuestion>() {}, gpQualityFeedbackQuestionUpdate);
        return toAjax(iGpQualityFeedbackQuestionService.updateById(gpQualityFeedbackQuestion) ? 1 : 0);
    }


    /**
     * @Description 导出
     * @Author gpframework
     * @Date 2023-12-14
     * @Param gpQualityFeedbackQuestion
     * @Return TableDataInfo
     */

    @PreAuthorize("@ss.hasPermi('module:feedbackquestion:export')" )
    @Log(title = "导出品质反馈问题" , businessType = BusinessType.EXPORT)
    @GetMapping("/export" )
    public AjaxResult export(GpQualityFeedbackQuestionReq gpQualityFeedbackQuestionReq) {
        QueryWrapper<GpQualityFeedbackQuestion> lqw = new QueryWrapper<GpQualityFeedbackQuestion>();
        gpQualityFeedbackQuestionReq.generatorQuery(lqw,true);
        List<GpQualityFeedbackQuestionVo> list = iGpQualityFeedbackQuestionService.listVo(lqw);
        ExcelUtil<GpQualityFeedbackQuestionVo> util = new ExcelUtil<GpQualityFeedbackQuestionVo>(GpQualityFeedbackQuestionVo. class);
        return util.exportExcel(list, "feedbackquestion" );
    }

    /**
     * @Description 详情
     * @Author gpframework
     * @Date 2023-12-14
     * @Param gpQualityFeedbackQuestion
     * @Return TableDataInfo
     */
    @ApiOperation("详情")
    @PreAuthorize("@ss.hasPermi('module:feedbackquestion:query')" )
    @GetMapping(value = "/{id}" )
    public AjaxResult<GpQualityFeedbackQuestionVo> getInfo(@PathVariable("id" ) Long id) {
        return AjaxResult.success(iGpQualityFeedbackQuestionService.getVoById(id));
    }



    /**
     * @Description 删除
     * @Author gpframework
     * @Date 2023-12-14
     * @Param gpQualityFeedbackQuestion
     * @Return TableDataInfo
     */
    @ApiOperation("删除")
    @PreAuthorize("@ss.hasPermi('module:feedbackquestion:remove')" )
    @Log(title = "删除品质反馈问题" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}" )
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(iGpQualityFeedbackQuestionService.removeByIds(Arrays.asList(ids)) ? 1 : 0);
    }


    /**
     * @Description 查询回复类型
     * @Author gpframework
     * @Date 2023-12-14
     * @Param gpQualityFeedbackQuestion
     * @Return TableDataInfo
     */
    @ApiOperation("查询回复类型")
    @PreAuthorize("@ss.hasPermi('module:feedbackquestion:list')" )
    @GetMapping("/selectReplyTypeList")
    public TableDataInfo<GpQualityFeedbackQuestionVo> selectReplyTypeList() {
        startPage();
        List<GpQualityFeedbackQuestionVo> replyTypeList = iGpQualityFeedbackQuestionService.replyTypeList();
        for (GpQualityFeedbackQuestionVo gpQualityFeedbackQuestionVo : replyTypeList) {
            List<GpQualityFeedbackQuestionVo> replyContentList = iGpQualityFeedbackQuestionService.replyContent(gpQualityFeedbackQuestionVo.getReplyType());
            gpQualityFeedbackQuestionVo.setReplyContentList(replyContentList);
        }

        return getDataTable(replyTypeList);
    }

}
